<?php 
// +----------------------------------------------------------------------
// | Item         初始化管理员数据
// +----------------------------------------------------------------------
// | Copyright
// +----------------------------------------------------------------------
// | Versions
// +----------------------------------------------------------------------
// | Author       YanHao
// +----------------------------------------------------------------------
// | Date         2017-07-05
// +----------------------------------------------------------------------

namespace app\admin\modeldata;

use think\helper\Hash;
use think\Db;

class Admin 
{

    /**
     * 数据初始化数组
     * @Author  YanHao
     * @Date    2017-07-05
     * @version [version]
     * @return  [type]     [description]
     */
    public static function data()
    {
        return [
          ['user' => 'admin', 'name'=> '超级管理员', 'password' => self::_setPwd('123456'), 'phone' => 18595802905]
        ];
    }

    /**
     * 加密密码
     * @Author  YanHao
     * @Date    2017-07-05
     * @version [version]
     * @param   [type]     $value [description]
     */
    private static function _setPwd($value)
    {
        return Hash::make($value);
    }

    /**
     * 执行
     * @Author  YanHao
     * @Date    2017-07-05
     * @version [version]
     * @return  [type]     [description]
     */
    public static function perform()
    {
        Db::name('admin')->execute('TRUNCATE tp_admin');

        foreach(self::data() as $v) {
            Db::name('admin')->insert($v);
        }
        return 0;
    }
        
}